home *** CD-ROM | disk | FTP | other *** search
- head 1.5;
- branch ;
- access ;
- symbols sprited:1.5.1;
- locks ; strict;
- comment @ * @;
-
-
- 1.5
- date 91.07.22.10.42.58; author ouster; state Exp;
- branches 1.5.1.1;
- next 1.4;
-
- 1.4
- date 91.07.22.10.22.12; author ouster; state Exp;
- branches ;
- next 1.3;
-
- 1.3
- date 88.07.28.17.50.10; author ouster; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 88.06.21.10.20.09; author ouster; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 88.06.19.16.56.01; author ouster; state Exp;
- branches ;
- next ;
-
- 1.5.1.1
- date 92.01.26.17.17.19; author kupfer; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
- 1.5
- log
- @Found another malloc and another free to eliminate.
- @
- text
- @/*
- * execvp.c --
- *
- * Source code for the execvp library procedure.
- *
- * Copyright 1988 Regents of the University of California
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies. The University of California
- * makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without
- * express or implied warranty.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: execvp.c,v 1.3 88/07/28 17:50:10 ouster Exp $ SPRITE (Berkeley)";
- #endif not lint
-
- #include <string.h>
- #include <stdlib.h>
- #include <errno.h>
-
- /*
- * Library imports:
- */
-
- extern char **environ;
- extern execve();
-
-
- /*
- *-----------------------------------------------------------------------
- *
- * DoExec --
- *
- * Function to actually execute a program. If the exec didn't succeed
- * because the file isn't in a.out format, attempt to execute
- * it as a bourne shell script.
- *
- * Results:
- * None. Doesn't even return unless the exec failed.
- *
- * Side Effects:
- * A program may be execed over this one.
- *
- *-----------------------------------------------------------------------
- */
-
- static void
- DoExec(file, argv)
- char *file; /* File to execute. */
- char **argv; /* Arguments to the program. */
- {
- execve(file, argv, environ);
- if (errno == ENOEXEC) {
- /*
- * Attempt to execute the file as a shell script using
- * the Bourne shell)
- */
- register int i;
- #define MAX_ARGS 1000
- char *newArgv[MAX_ARGS+1];
-
- for (i = 0; argv[i] != 0; i++) {
- /* Empty loop body */
- }
- if (i >= MAX_ARGS) {
- return;
- }
- newArgv[0] = "sh";
- newArgv[1] = file;
- for (i = 1; argv[i] != 0; i++) {
- newArgv[i+1] = argv[i];
- }
- newArgv[i+1] = 0;
- execve("/sprite/cmds/sh", newArgv, environ);
- }
- }
-
- /*
- *----------------------------------------------------------------------
- *
- * execvp --
- *
- * Execute a process, using the current environment variable,
- * instead of an explicitly-supplied one. Also, imitate the
- * shell's actions in trying each directory in a search path
- * (given by the "PATH" environment variable).
- *
- * Results:
- * This procedure returns only if the exec fails. In this case
- * the return value is -1.
- *
- * Side effects:
- * Overlays the current process with a new image. See the man
- * page for details.
- *
- *----------------------------------------------------------------------
- */
-
- int
- execvp(name, argv)
- char *name; /* Name of file containing program to exec. */
- char **argv; /* Array of arguments to pass to program. */
- {
- char *path;
- #define MAX_NAME_SIZE 1000
- char fullName[MAX_NAME_SIZE+1];
- register char *first, *last;
- int nameLength, size, noAccess;
-
- noAccess = 0;
-
- if (index(name, '/') != 0) {
- /*
- * If the name specifies a path, don't search for it on the search path,
- * just try and execute it.
- */
- DoExec(name, argv);
- return -1;
- }
-
- path = getenv("PATH");
- if (path == 0) {
- path = "/sprite/cmds";
- }
- nameLength = strlen(name);
- for (first = path; ; first = last+1) {
-
- /*
- * Generate the next file name to try.
- */
-
- for (last = first; (*last != 0) && (*last != ':'); last++) {
- /* Empty loop body. */
- }
- size = last-first;
- if ((size + nameLength + 2) >= MAX_NAME_SIZE) {
- continue;
- }
- (void) strncpy(fullName, first, size);
- if (last[-1] != '/') {
- fullName[size] = '/';
- size++;
- }
- (void) strcpy(fullName + size, name);
-
- DoExec(fullName, argv);
- if (errno == EACCES) {
- noAccess = 1;
- } else if (errno != ENOENT) {
- break;
- }
- if (*last == 0) {
- /*
- * Hit the end of the path. We're done.
- * If there existed a file by the right name along the search path,
- * but its permissions were wrong, return FS_NO_ACCESS. Else return
- * whatever we just got back.
- */
- if (noAccess) {
- errno = EACCES;
- }
- break;
- }
- }
- return -1;
- }
- @
-
-
- 1.5.1.1
- log
- @Initial branch for Sprite server.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/exec/RCS/execvp.c,v 1.5 91/07/22 10:42:58 ouster Exp $ SPRITE (Berkeley)";
- @
-
-
- 1.4
- log
- @Can't use malloc: after vfork, memory can be shared with parent,
- so malloc causes parent to lose memory.
- @
- text
- @a60 1
- register char **newargv;
- d62 2
- d68 5
- a72 3
- newargv = (char **) malloc((unsigned) ((i+1)*sizeof (char *)));
- newargv[0] = "sh";
- newargv[1] = file;
- d74 1
- a74 1
- newargv[i+1] = argv[i];
- d76 2
- a77 2
- newargv[i+1] = 0;
- execve("/sprite/cmds/sh", newargv, environ);
- a167 1
- free((char *) fullName);
- @
-
-
- 1.3
- log
- @Lint.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: execvp.c,v 1.2 88/06/21 10:20:09 ouster Exp $ SPRITE (Berkeley)";
- d105 2
- a106 1
- char *fullName;
- d108 1
- a108 1
- int size, noAccess;
- d125 1
- a125 1
- fullName = malloc((unsigned) (strlen(name) + strlen(path)) + 2);
- d136 3
- @
-
-
- 1.2
- log
- @Use string.h instead of strings.h.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: execvp.c,v 1.1 88/06/19 16:56:01 ouster Exp $ SPRITE (Berkeley)";
- d116 1
- a116 1
- DoExec(name, argv, environ);
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
- d20 1
- a20 1
- #include <strings.h>
- @
-